<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
namespace core;
defined('BY_JYA') or exit('error');
class ssr{
	public function sitemap() {
		$params=array();	
		$links=array();
		$txturl='';
		$xmlurl='';
		$list=pdo_getall('core_account_group',$params,array('id','title'),'','id desc');
		$links['group']=array(
				'title'=>'服务套餐/场景套餐',
				'url'=>manage_url('core/home.group_store/list/',true)
		);
		$txturl .=$links['group']['url']."\n";
		$xmlurl .="<url><loc>".$links['group']['url']."</loc><lastmod></lastmod><changefreq></changefreq><priority>0.8</priority></url>\n";
		foreach($list as $item){		
			$links['group']['apps'][]=array(
				'title'=>$item['title'],
				'url'=>manage_url('core/home.group_store/detail/id='.$item['id'],true)
			);
			$url=manage_url('core/home.group_store/detail/id='.$item['id'],true);
			$txturl .=$url."\n";
			$xmlurl .="<url><loc>".$url."</loc><lastmod></lastmod><changefreq></changefreq><priority>0.8</priority></url>\n";
		}
		$list=pdo_getall('core_article_group',$params,array('id','title'),'','id desc');
		$links['news']=array(
				'title'=>'新闻动态',
				'url'=>manage_url('core/home.news/list/',true)
		);
		$url=manage_url('core/home.news/list/',true);
		$txturl .=$url."\n";
		$xmlurl .="<url><loc>".$url."</loc><lastmod></lastmod><changefreq></changefreq><priority>0.8</priority></url>\n";
		foreach($list as $item){		
			$links['news']['apps'][]=array(
				'title'=>$item['title'],
				'url'=>manage_url('core/home.news/detail/id='.$item['id'],true)
			);
			$url=manage_url('core/home.news/detail/id='.$item['id'],true);
			$txturl .=$url."\n";
			$xmlurl .="<url><loc>".$url."</loc><lastmod></lastmod><changefreq></changefreq><priority>0.8</priority></url>\n";
		}
		if(!file_exists(ROOT_AT.'sitemap')){
			mkdir(ROOT_AT.'sitemap',0700, true);
		}
		file_put_contents(ROOT_AT.'sitemap/sitemap.txt',$txturl);
		$xmlurl=str_replace('&','&amp;',$xmlurl);
		$sitemapxml=$this->xml($xmlurl);
		file_put_contents(ROOT_AT.'sitemap/sitemap.xml',$sitemapxml);
	}
	public function xml($xmlurl) {
		$xml=<<<TPL
<?xml version="1.0" encoding="utf-8"?>
<urlset>
{$xmlurl}
</urlset>
TPL;
		return ltrim($xml);
	}
}